package destiny.music;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import android.os.Environment;

public class FileUit {
	private String SDPath;

	public String getSDPath() {
		return SDPath;
	}

	public FileUit() {
		SDPath = Environment.getExternalStorageDirectory() + "/";
	}
	public File createSDFile(String fileName) throws IOException
	{
		File file = new File(SDPath+fileName);
		file.createNewFile();
		return file;
	}
	public File createSDDir(String dirName)
	{
		File dir = new File(SDPath+dirName);
		dir.mkdirs();
		return dir;
		
	}
	public boolean isFileExist(String fileName)
	{
		File is = new File(SDPath+fileName);
		return is.exists();
	}
	public File writeToSDFromInput(String path,String fileName,InputStream input)
	{
		File file = null;
		OutputStream output = null;
		try {
			createSDDir(path);
			file = createSDFile(path+fileName);
			output = new FileOutputStream(file);
			byte[] buffer = new byte[8*1024];
			int tmp;
			while((tmp=input.read(buffer))!=-1)
			{
				output.write(buffer,0,tmp);
			}
			output.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	/*public List<Mp3Info> getMp3Infos(String path)
	{
		List<Mp3Info> list = new ArrayList<Mp3Info>();
		File file = new File(SDPath+File.separator+path);
		File[] files = file.listFiles();
		for(int i=0;i<files.length;i++)
		{
			if(files[i].getName().endsWith("mp3"))
			{
				Mp3Info mp3info = new Mp3Info();
				mp3info.setId(i+"");
				mp3info.setMp3Name(files[i].getName());
				mp3info.setMp3Size(files[i].length()+"");
				list.add(mp3info);
			}
		}
		return list;
	}*/
}
